package algorithm.poj.p3000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.Arrays;


/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验和教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P3006 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P3006.class.getResource("P3006.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		int[] ps = primes(1000001);
		String line = stdin.readLine();
		while (line != null && !"0 0 0".equals(line.trim())) {
			String[] tmp = line.trim().split(" ");
			int a = Integer.valueOf(tmp[0]);
			int d = Integer.valueOf(tmp[1]);
			int n = Integer.valueOf(tmp[2]);
			System.out.println(dirichlet(a, d, n, ps));
			line = stdin.readLine();
		}
	}
	
	private static int dirichlet(int a, int d, int n, int[] ps) {
		
		int count = 0;
		int p = a;
		while (count < n) {
			if (Arrays.binarySearch(ps, p) >= 0) {
				count ++;
			}
			p += d;
		}
		return p-d;
	}

	/**
	 * return all primes less than m 
	 * @param m
	 * @return
	 */
	private static int[] primes(int m) {
		
		if (m <= 1) {
			return new int[0];
		} else if (m == 2) {
			return new int[] {2};
		} else {
			int count = 0;
			int[] ns = new int[m];
			for (int i = 0; i < m; i ++) ns[i] = i;
			ns[0] = ns[1] = 0;
			
			int index = 2;
			int p = 0;
			while (index < m) {
				if (ns[index] != 0) {
					count ++;
					p = index;
					for (int j = (p<<1); j < m; j += p) {
						ns[j] = 0;
					}
				}
				index ++;
			}
			
			index = 0;
			int[] ps = new int[count];
			for (int i = 0; i < m; i ++) {
				if (ns[i] != 0) {
					ps[index ++] = i;
				}
			}

			return ps;
		}
	}
}